/**
 * 
 */
package com.topu.db.io;

import java.io.File;

import org.dom4j.Element;

import com.topu.xml.XmlUtils;
import com.topu.db.model.DBFactory;
import com.topu.db.model.IDBFactory;

/**
 * @author popofish
 * 
 */
public class DBFactoryReader implements IDBFactoryReader {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.topu.db.io.IDBFactoryReader#read(java.lang.String)
	 */
	@Override
	public IDBFactory read(String dbConfFile) {
		try {
			DBFactory factory = new DBFactory();
			File file = new File(dbConfFile);
			if (!file.exists()) {
				throw new NullPointerException(dbConfFile + " is not exist!");
			}
			String path = file.getAbsolutePath();
			factory.setConfigFilePath(path);
			Element root = XmlUtils.readAsRootElement(path);
			factory.read(root);
			return factory;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return null;
	}
}
